<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "news_tag_rela".
 *
 * @property integer $id
 * @property integer $newsid
 * @property integer $tagid
 * @property string $tagname
 */
class NewsTagRela extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'news_tag_rela';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['newsid', 'tagid'], 'integer'],
            [['tagname'], 'string', 'max' => 100],
            [['newsid', 'tagid'], 'unique', 'targetAttribute' => ['newsid', 'tagid'], 'message' => 'The combination of Newsid and Tagid has already been taken.'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'newsid' => 'Newsid',
            'tagid' => 'Tagid',
            'tagname' => 'Tagname',
        ];
    }

    public static function getTagidByNewsid( $newsid ){
        if( !$newsid ) return array();
        return self::find()->where(['newsid' => $newsid])->asArray()->all();
    }
}
